package com.dtborad.myblog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dtborad.myblog.entity.Comments;
import com.dtborad.myblog.entity.Posts;
import com.dtborad.myblog.entity.Tags;
import com.dtborad.myblog.mapper.CommentsMapper;
import com.dtborad.myblog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements CommentService {

    @Autowired
    private CommentsMapper commentsMapper;
    @Override
    public Page<Comments> getAllCommentsByPageSize(int page, int pageSize, Integer postid, String commentcontent) {
        LambdaQueryWrapper<Comments> wrapper = new LambdaQueryWrapper<>();
        // 根据 postid 过滤
        if (postid != null) {
            wrapper.eq(Comments::getPostid, postid);
        }

        // 根据 commentcontent 过滤
        if (StrUtil.isNotBlank(commentcontent)) {
            wrapper.like(Comments::getCommentcontent, commentcontent);
        }

        // 分页查询
        return commentsMapper.selectPage(new Page<>(page, pageSize), wrapper);
    }
}
